using System.Collections;
using System.Collections.Generic;
using Framework.Library.Core.Utils.Miscellaneous;

namespace Framework.Library.Core.Utils.Collections
{
    public class EnumerableWrapper<T> : IEnumerable<T>
    {
        private readonly bool _convertNonCompatibleType;
        private readonly bool _defaultOnBadType;
        private readonly IEnumerable _enumerable;

        public EnumerableWrapper(IEnumerable e)
            : this(e, false, false)
        {
        }

        public EnumerableWrapper(IEnumerable e, bool defaultOnBadType, bool convertNonCompatibleType)
        {
            ValidationUtils.ArgumentNotNull(e, "e");

            _defaultOnBadType = defaultOnBadType;
            _convertNonCompatibleType = convertNonCompatibleType;
            _enumerable = e;
        }

        public bool DefaultOnBadType
        {
            get { return _defaultOnBadType; }
        }

        public bool ConvertNonCompatibleType
        {
            get { return _convertNonCompatibleType; }
        }

        #region IEnumerable<T> Members

        public IEnumerator<T> GetEnumerator()
        {
            return new EnumeratorWrapper<T>(_enumerable.GetEnumerator(), _defaultOnBadType, _convertNonCompatibleType);
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        #endregion
    }
}